import { createStore, applyMiddleware, compose } from 'redux'
import reducer from './reducer'
// redux 的中间件
// import thunk from 'redux-thunk'
// saga的中间件
import createSagaMiddleware from 'redux-saga'
import todoSagas from './sagas'
// create the saga middleware
const sagaMiddleware = createSagaMiddleware()

const composeEnhancers =
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
      // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
    }) : compose

const enhancer = composeEnhancers(
  applyMiddleware(sagaMiddleware),
  // other store enhancers if any
);

// 创建仓库 并掌管数据
const store = createStore(reducer,
  enhancer
)
// then run the saga
sagaMiddleware.run(todoSagas)

export default store